//
//  HRDynamicSectionView.m
//  Hear
//
//  Created by mac on 2018/1/23.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "HRDynamicSectionView.h"
@interface HRDynamicSectionView ()
@property (nonatomic,strong)UILabel *selectLine;
@end
@implementation HRDynamicSectionView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self){
        UILabel *topLineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 1)];
        topLineLabel.backgroundColor = CustomColor(240, 240, 240, 1);
        [self addSubview:topLineLabel];
        
        CGFloat buttonWidth = kScreenWidth/3;
        NSArray *textArr  = @[@" 点滴",@" 留声机",@" 自创话题"];
        NSArray *imageArr  = @[@"瞬间",@"留声机",@"话题"];
        for (int i =0; i < textArr.count; i ++) {
            UIButton *button = [UIButton buttonWithType:0];
            [button setTitle:textArr[i] forState:0];
            button.titleLabel.font = CustomUIFont(14);
            [button setTitleColor:FirstTextColor forState:0];
            [self addSubview:button];
            [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
            [button setImage:[UIImage imageNamed:imageArr[i]] forState:0];
            button.frame = CGRectMake(i*buttonWidth, 1, buttonWidth, frame.size.height-2);
            button.tag = i;
            if (i ==0){
                UILabel *selectLine = [[UILabel alloc] initWithFrame:CGRectMake(0, frame.size.height-2, button.width, 2)];
                selectLine.backgroundColor = FirstTextColor;
                [self addSubview:(self.selectLine=selectLine)];
            }
        }
        UILabel *bottomLineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, frame.size.height-1, frame.size.width, 1)];
        bottomLineLabel.backgroundColor = CustomColor(240, 240, 240, 1);
        [self addSubview:bottomLineLabel];
        
        
        
    }
    return self;
}
- (void)buttonClick:(UIButton*)button{
    WeakSelf
    [UIView animateWithDuration:0.3 animations:^{
        weakSelf.selectLine.left = button.left;
    }];
    if (self.selectIndexBlock){
        self.selectIndexBlock(button.tag);
    }
}


@end
